-- | Calculate the block-wise entropy of a malware file. See the paper
-- | of ...

module Hexena.Cmds.CalcBlockEntropy (run) where

import Control.Monad (when)

import Hexena.Chunks
import Hexena.Modules.BlockEntropy


run :: String -> IO ()
run fn = do
  (dat, rawiff) <- loadMalwIFF' fn
  let already = alreadyAnalysed rawiff
  print already
  results <- analyse rawiff
  when (not $ checkPrerequisites rawiff) $ putStrLn "Malware file has no BODY. Aborting!"
  print results
  if already then
      putStrLn "Analysis was found in hexena file!"
   else
      writeIFF fn (serialise results:rawiff)